using System;
using System.Data;
using System.Collections.Generic;

namespace SERP.DAO{
	/********************************BEGIN OrganizationsDAO****************************************/
	///<summary>
	/// <para>Author: Auto generated class by CSharp Code Generator v2.0</para>
	/// <para>Date:09/03/2013 19:09:04</para>
	/// <para>Class Name: OrganizationsDAO</para>
	/// <para>Description: Class access to table Organizations in database. Coder should'nt code here.</para>
	///</summary>

	
	public partial class OrganizationsDAO : DAOBase<OrganizationsEntity>{


		#region Select functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectOneCommand</para>
		/// <para>Input: OrganizationId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectOneCommand(int OrganizationId){
			string strSQL="SELECT  [OrganizationId],[ParentId],[OrgCode],[OrgName],[Note],[OrgType] FROM [Organizations]  WHERE [Organizations].[OrganizationId]=@OrganizationId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@OrganizationId",OrganizationId);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectOne</para>
		/// <para>Input: OrganizationId</para>
		/// <para>Output: OrganizationsEntity</para>
		///</summary>
		public OrganizationsEntity SelectOne(int OrganizationId){
			IDbCommand cmd=this.CreateSelectOneCommand(OrganizationId);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllCommand(){
			string strSQL="SELECT  [OrganizationId],[ParentId],[OrgCode],[OrgName],[Note],[OrgType] FROM [Organizations] ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllByKeyCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyCommand(string ColumnName,object Value){
			string strSQL="SELECT  [OrganizationId],[ParentId],[OrgCode],[OrgName],[Note],[OrgType] FROM [Organizations]  WHERE [Organizations].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of OrganizationsEntity</para>
		///</summary>
		public List<OrganizationsEntity> SelectAll(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAllDS</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDS(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectDS(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllFilterCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllFilterCommand(string strFilter){
			string strSQL="SELECT  [OrganizationId],[ParentId],[OrgCode],[OrgName],[Note],[OrgType] FROM [Organizations]  WHERE "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllByKeyFilterCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyFilterCommand(string strFilter,string ColumnName,object Value){
			string strSQL="SELECT  [OrganizationId],[ParentId],[OrgCode],[OrgName],[Note],[OrgType] FROM [Organizations]  WHERE [Organizations].["+ColumnName+"]=@ColumnName AND "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of OrganizationsEntity</para>
		///</summary>
		public List<OrganizationsEntity> SelectAllFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAllDSFilter</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDSFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectDS(cmd);
		}
		#endregion

		#region Insert functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateInsertCommand</para>
		/// <para>Input: OrganizationsEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateInsertCommand(OrganizationsEntity o){
			string strSQL="INSERT INTO [Organizations]([ParentId],[OrgCode],[OrgName],[Note],[OrgType]) VALUES  (@ParentId,@OrgCode,@OrgName,@Note,@OrgType);SELECT  @@IDENTITY";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullParentId)
				this.CreateCommandParameter(cmd,"@ParentId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@ParentId",o.ParentId);

			if(o.IsNullOrgCode)
				this.CreateCommandParameter(cmd,"@OrgCode",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@OrgCode",o.OrgCode);

			if(o.IsNullOrgName)
				this.CreateCommandParameter(cmd,"@OrgName",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@OrgName",o.OrgName);

			if(o.IsNullNote)
				this.CreateCommandParameter(cmd,"@Note",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@Note",o.Note);

			if(o.IsNullOrgType)
				this.CreateCommandParameter(cmd,"@OrgType",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@OrgType",o.OrgType);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Save</para>
		/// <para>Input: OrganizationsEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Save(OrganizationsEntity o){
			bool result=false;
			IDbCommand cmd=this.CreateInsertCommand(o);
			object id=this.ExecuteScalar(cmd,ref result);
			cmd.Dispose();
			try{
				o.OrganizationId=int.Parse(Convert.ToString(id));
			}
			catch{}
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SaveList</para>
		/// <para>Input: List of OrganizationsEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void SaveList(List<OrganizationsEntity>list){
			foreach(OrganizationsEntity o in list){
				try{
					this.Save(o);
				}
				catch{
				}
			}
		}
		#endregion

		#region Update functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateUpdateCommand</para>
		/// <para>Input: OrganizationsEntity</para>
		/// <para>Output: </para>
		///</summary>
		protected IDbCommand CreateUpdateCommand(OrganizationsEntity o){
			string strSQL="UPDATE  [Organizations] SET [Organizations].[ParentId]=@ParentId,[Organizations].[OrgCode]=@OrgCode,[Organizations].[OrgName]=@OrgName,[Organizations].[Note]=@Note,[Organizations].[OrgType]=@OrgType WHERE [Organizations].[OrganizationId]=@OrganizationId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullParentId)
				this.CreateCommandParameter(cmd,"@ParentId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@ParentId",o.ParentId);

			if(o.IsNullOrgCode)
				this.CreateCommandParameter(cmd,"@OrgCode",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@OrgCode",o.OrgCode);

			if(o.IsNullOrgName)
				this.CreateCommandParameter(cmd,"@OrgName",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@OrgName",o.OrgName);

			if(o.IsNullNote)
				this.CreateCommandParameter(cmd,"@Note",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@Note",o.Note);

			if(o.IsNullOrgType)
				this.CreateCommandParameter(cmd,"@OrgType",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@OrgType",o.OrgType);

			if(o.IsNullOrganizationId)
				this.CreateCommandParameter(cmd,"@OrganizationId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@OrganizationId",o.OrganizationId);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateUpdateFieldCommand</para>
		/// <para>Input: ColumnName,ColumnValue,OrganizationId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateUpdateFieldCommand(string ColumnName,object Value,int OrganizationId){
			string strSQL="UPDATE  [Organizations] SET [Organizations].["+ColumnName+"]=@ColumnName WHERE [Organizations].[OrganizationId]=@OrganizationId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@OrganizationId",OrganizationId);



			this.CreateCommandParameter(cmd,"@ColumnName",Value);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Update</para>
		/// <para>Input: OrganizationsEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Update(OrganizationsEntity o){
			IDbCommand cmd=this.CreateUpdateCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateList</para>
		/// <para>Input: List of OrganizationsEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void UpdateList(List<OrganizationsEntity>list){
			foreach(OrganizationsEntity o in list){
				try{
					this.Update(o);
				}
				catch{
				}
			}
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateParentId</para>
		/// <para>Input: NewParentId,OrganizationId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateParentId(int NewParentId,int OrganizationId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("ParentId",NewParentId,OrganizationId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateOrgCode</para>
		/// <para>Input: NewOrgCode,OrganizationId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateOrgCode(string NewOrgCode,int OrganizationId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("OrgCode",NewOrgCode,OrganizationId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateOrgName</para>
		/// <para>Input: NewOrgName,OrganizationId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateOrgName(string NewOrgName,int OrganizationId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("OrgName",NewOrgName,OrganizationId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateNote</para>
		/// <para>Input: NewNote,OrganizationId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateNote(string NewNote,int OrganizationId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("Note",NewNote,OrganizationId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateOrgType</para>
		/// <para>Input: NewOrgType,OrganizationId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateOrgType(Byte NewOrgType,int OrganizationId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("OrgType",NewOrgType,OrganizationId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Delete functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteAllCommand(){
			string strSQL="DELETE   FROM [Organizations]  ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteCommand</para>
		/// <para>Input: OrganizationsEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteCommand(OrganizationsEntity o){
			string strSQL="DELETE   FROM [Organizations]   WHERE [Organizations].[OrganizationId]=@OrganizationId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullOrganizationId)
				this.CreateCommandParameter(cmd,"@OrganizationId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@OrganizationId",o.OrganizationId);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteAll</para>
		/// <para>Input: </para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteAll(){
			IDbCommand cmd=this.CreateDeleteAllCommand();
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateDeleteByPrimaryKeyCommand</para>
		/// <para>Input: OrganizationId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByPrimaryKeyCommand(int OrganizationId){
			string strSQL="DELETE   FROM [Organizations]   WHERE [Organizations].[OrganizationId]=@OrganizationId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@OrganizationId",OrganizationId);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateDeleteByKeyCommand</para>
		/// <para>Input: ColumnName , ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByKeyCommand(string ColumnName,object Value){
			string strSQL="DELETE   FROM [Organizations]   WHERE [Organizations].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Delete</para>
		/// <para>Input: OrganizationsEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Delete(OrganizationsEntity o){
			IDbCommand cmd=this.CreateDeleteCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteByID</para>
		/// <para>Input: OrganizationId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteByID(int OrganizationId){
			IDbCommand cmd=this.CreateDeleteByPrimaryKeyCommand(OrganizationId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Select join to Organizations functions
		#endregion

		#region Select,delete by OrganizationId functions
		#endregion

		#region Select,delete by ParentId functions
		#endregion

		#region MapObject functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: MapObject</para>
		/// <para>Input: IDataReader</para>
		/// <para>Output: OrganizationsEntity</para>
		///</summary>
		protected override OrganizationsEntity MapObject(IDataReader r){
			OrganizationsEntity entity = new OrganizationsEntity();
			try{
				if(r.FieldCount>0){
					try
					{
						int ordinal = r.GetOrdinal("OrganizationId");
						if (!r.IsDBNull(ordinal)) entity.OrganizationId = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("ParentId");
						if (!r.IsDBNull(ordinal)) entity.ParentId = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("OrgCode");
						if (!r.IsDBNull(ordinal)) entity.OrgCode = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("OrgName");
						if (!r.IsDBNull(ordinal)) entity.OrgName = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("Note");
						if (!r.IsDBNull(ordinal)) entity.Note = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("OrgType");
						if (!r.IsDBNull(ordinal)) entity.OrgType = ((Byte)(r.GetValue(ordinal)));
					}
					catch{}
					return entity;
				}
			}catch{}
			return null;
		}
		#endregion
	}
	/*****************************************************************************************************/
	/**********************************END OrganizationsDAOBase*****************************************/
	/*****************************************************************************************************/
}

